package com.CST.controller.cb;

import com.CST.common.api.ResultObject;
import com.CST.dto.cb.SysRoleMenuDTO;
import com.CST.service.cb.IBdSysRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>角色菜单管理</p>
 *
 * @author: y
 * @create: 2021-09-28 09:19
 **/
@Api(tags = {"角色菜单管理"})
@RestController
@RequestMapping("/bdSysRoleMenu")
@Log4j2
public class BdSysRoleMenuController {

    @Autowired
    private IBdSysRoleMenuService bdSysRoleMenuService;

    /**
     * <p>新建角色菜单列表</p >
     * @param sysRoleMenuDto
     * @author y
     * @since 2021/09/28 09:43
     * @return com.CST.common.api.ResultObject
     */
    @ApiOperation(value = "新建角色菜单列表", notes = "新建角色菜单列表")
    @PostMapping("/insertSysRoleMenu")
    public ResultObject insertSysRoleMenu(@RequestBody SysRoleMenuDTO sysRoleMenuDto) {
        return ResultObject.successReturn(bdSysRoleMenuService.insertSysRoleMenu(sysRoleMenuDto));
    }

    /**
     * <p>删除角色菜单</p >
     * @param id
     * @author y
     * @since 2021/09/28 10:11
     * @return com.CST.common.api.ResultObject
     */
    @ApiOperation(value = "删除角色菜单", notes = "删除角色菜单")
    @PostMapping("/deleteRoleMenu")
    public ResultObject deleteRoleMenu(@RequestParam String id){
        if (bdSysRoleMenuService.deleteSysRoleMenuById(id)) {
            return ResultObject.successReturn("删除角色菜单成功");
        } else {
            return ResultObject.errorReturn("删除角色菜单失败");
        }
    }

    /**
     * <p>修改角色菜单</p >
     * @param sysRoleMenuDto
     * @author y
     * @since 2021/09/28 10:50
     * @return int
     */
    @ApiOperation("修改角色菜单")
    @PostMapping ("/updateSysRoleMenu")
    public ResultObject updateSysRoleMenu(@RequestBody SysRoleMenuDTO sysRoleMenuDto){
        return ResultObject.successReturn(bdSysRoleMenuService.updateSysRoleMenu(sysRoleMenuDto));
    }

    /**
     * <p>id查询详情</p >
     * @param id
     * @author y
     * @since 2021/09/28 10:51
     * @return com.CST.common.api.ResultObject
     */
    @ApiOperation("id查询详情")
    @GetMapping("/getSysRoleMenuById")
    public ResultObject getSysRoleMenuById(@RequestParam String id) {
        return ResultObject.successReturn(bdSysRoleMenuService.getSysRoleMenuById(id));
    }

    /**
     * <p>根据角色或菜单查询</p >
     * @param roleId, menuId
     * @author y
     * @since 2021/09/28 14:22
     * @return com.CST.common.api.ResultObject
     */
    @ApiOperation("根据角色或菜单查询")
    @GetMapping("/getSysRoleMenu")
    public ResultObject getSysRoleMenu(@RequestParam("roleId") String roleId, @RequestParam("menuId") String menuId) {
        return ResultObject.successReturn(bdSysRoleMenuService.getSysRoleMenu(roleId, menuId));
    }

}
